package com.woniuxy.store.core.controller;


import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.woniuxy.common.CommonResult;
import com.woniuxy.store.core.model.PlOrderitem;
import com.woniuxy.store.core.model.PmEvaluate;
import com.woniuxy.store.core.service.PmEvaluateService;
import com.woniuxy.store.core.vo.OrderItemVo;
import io.swagger.models.auth.In;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author gmx
 * @since 2021-07-05
 */
@RestController
@RequestMapping("pmEvaluate")
public class PmEvaluateController {
    @Resource
    private PmEvaluateService evaluateService;
    /**
     * Description : 查询门店所有订单项评价
     * ChangeLog : 1. 创建 (2021/7/5 11:53 [fulang]);
     * @param storeId
     * @return com.woniuxy.common.CommonResult<java.util.List<com.woniuxy.store.core.model.PmEvaluate>>
    */
//    @GetMapping("selectList/{storeId}")
//    public CommonResult<List<PmEvaluate>> selectList(@PathVariable Integer storeId){
//        List<PmEvaluate> pmEvaluates = evaluateService.selectList(storeId);
//        if (pmEvaluates!=null) {
//            return CommonResult.success(pmEvaluates);
//        }
//        return CommonResult.fail("加载失败");
//    };
    @GetMapping("selectList/{storeId}/{startpage}/{pagesize}")
    public PageInfo<PmEvaluate> selectList(@PathVariable Integer storeId, @PathVariable int startpage, @PathVariable int pagesize){
        PageHelper.startPage(startpage, pagesize);
        List<PmEvaluate> pmEvaluates = evaluateService.selectList(storeId);
        Page<PmEvaluate> page = (Page<PmEvaluate>) pmEvaluates;
        PageInfo<PmEvaluate> info = new PageInfo<>(page);
        return info;
    };
    /**
     * Description : 查看评价对应的订单详情。
     * ChangeLog : 1. 创建 (2021/7/5 12:11 [fulang]);
     * @param id
     * @return com.woniuxy.common.CommonResult<com.woniuxy.store.core.model.PlOrderitem>
    */
    @GetMapping("selectOrder/{id}")
    public CommonResult<PlOrderitem> selectOrder(@PathVariable Integer id){
        PlOrderitem orderitem = evaluateService.selectOrder(id);
        if (orderitem!=null){
            return CommonResult.success(orderitem);
        }
        return CommonResult.fail("加载失败");
    };
    /**
     * Description : 店家回复
     * ChangeLog : 1. 创建 (2021/7/5 14:13 [fulang]);
     * @param evaluate
     * @return com.woniuxy.common.CommonResult
    */
    @PostMapping("reply")
    public CommonResult reply(@RequestBody PmEvaluate evaluate){
        boolean b = evaluateService.updateById(evaluate);
        if (b==true){
            return CommonResult.success();
        }
        return CommonResult.fail("回复失败");
    }
    /**
     * Description : 根据评价查看订单详情
     * ChangeLog : 1. 创建 (2021/7/8 16:54 [fulang]);
     * @param id
     * @return com.woniuxy.store.core.model.PlOrderitem
    */
    @GetMapping("order/{id}")
    public List<PlOrderitem> order(@PathVariable Integer id){
        List<PlOrderitem> orderitem = evaluateService.selectOrderByEvaluate(id);
        return orderitem;
    }
}